<?php
/*
* MenuController.php
* Handle the CRUD for menu.
*/

require_once 'MenuModel.php';
require_once 'MenuView.php';

class MenuController
{
	private $databaseConnection = null;
	
	
	public function __construct( $databaseConnection ) 
	{
		$this->databaseConnection = $databaseConnection;
	}
	
	public function StartController()
	{
		$menuView = new MenuView();
		$menuModel = new MenuModel( $this->databaseConnection );
		
		$xhtml ='';
		
		if( $menuView->IsDeleteMenuSet() == true )
		{
			$menuModel->RemoveMenu( $menuView->GetDeleteMenu() );
		}
		
		if( $menuView->IsMenuNameSet() == true )
		{
			$menuModel->SaveMenu( $menuView->GetMenuName() );
		}
		
		$xhtml .= $menuView->DrawInputMenuView();
		
		$xhtml .= $menuView->DrawAllMenus( $menuModel->SelectAllMenus() );
		
		return $xhtml;
		
	}
	
}